package com.sinothk.droid.chart.demo;

import android.graphics.Color;
import android.os.Bundle;

import com.sinothk.droid.chart.barChartHorizontal.BarChartHorizontalManager;

import androidx.appcompat.app.AppCompatActivity;

import com.sinothk.droid.chart.barChartHorizontal.BarChartParam;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieEntry;
import com.sinothk.droid.chart.pieChart.PieChartManager;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    PieChart pieChart;
    HorizontalBarChart hBarChart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        pieChart = this.findViewById(R.id.pieChart);
        hBarChart = this.findViewById(R.id.hBarChart);

        initPieBar();
        initHBar();
    }

    private void initPieBar() {
        showhodlePieChart();
    }

    private void showhodlePieChart() {
        // 设置每份所占数量
        ArrayList<PieEntry> yvals = new ArrayList<>();
        yvals.add(new PieEntry(11f, "汉族"));
        yvals.add(new PieEntry(22f, "回族"));
        yvals.add(new PieEntry(33f, "壮族"));

        //设置每份的颜色
        ArrayList<Integer> colors = new ArrayList<>();
        colors.add(Color.parseColor("#6785f2"));
        colors.add(Color.parseColor("#675cf2"));
        colors.add(Color.parseColor("#496cef"));

        PieChartManager pieChartManager = new PieChartManager(pieChart);
        pieChartManager.showRingPieChart(yvals, colors, "万个");
    }

    private void initHBar() {
        String[] xSet = {"特惠大床房", "双床房", "一等房", "总统套房", "特色房"};
        float[] ySet = {50f, 20f, 30f, 40f, 150f};
        new BarChartHorizontalManager(this, hBarChart)
                .setParam(new BarChartParam())
                .setData(xSet, ySet)
                .show();
    }
}